import { Message } from 'element-ui'

interface HandleFun {
  [key: string]: Function
}

function handle200<T>() {}
function handle400<T>() {}
function handle401<T>() {}
function handle500<T>() {}
function handle403<T>() {}
function handle404<T>() {}
function handle502<T>() {}

function handle900200<T>(res: ApiResult<T>) {
  return Promise.resolve(res.data)
}
function handle900400<T>(res: ApiResult<T>) {
  return Promise.reject(res.error)
}
function handle900401<T>(res: ApiResult<T>) {
  return Promise.reject(res.error)
}
function handle900403<T>(res: ApiResult<T>) {
  return Promise.reject(res.error)
}
function handle900404<T>(res: ApiResult<T>) {
  return Promise.reject(res.error)
}
function handle900500<T>(res: ApiResult<T>) {
  return Promise.reject(res.error)
}
function handle900502<T>(res: ApiResult<T>) {
  return Promise.reject(res.error)
}

const handle: HandleFun = {
  '200': handle200,
  '400': handle400,
  '401': handle401,
  '403': handle403,
  '404': handle404,
  '500': handle500,
  '502': handle502,
  '900200': handle900200,
  '900400': handle900400,
  '900401': handle900401,
  '900403': handle900403,
  '900404': handle900404,
  '900500': handle900500,
  '900502': handle900502
}

export default handle
